<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="文件编号" prop="docDjbh">
        <el-input
          v-model="queryParams.docDjbh"
          placeholder="请输入文件编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模具编号" prop="docMjbh">
        <el-input
          v-model="queryParams.docMjbh"
          placeholder="请输入模具编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户编码" prop="docCustwldm">
        <el-input
          v-model="queryParams.docCustwldm"
          placeholder="请输入客户编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图纸编号" prop="docTzbh">
        <el-input
          v-model="queryParams.docTzbh"
          placeholder="请输入图纸编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件类型" prop="docType">
        <el-select
          v-model="queryParams.docType"
          placeholder="请选择文件类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in docTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['project:docList:export']"
        >
          导出
        </el-button>
      </el-col>
      <el-col :span="2.2" style="position: absolute; right: 35px; top: 0">
        <Page
          style="margin-right: 0px"
          :current="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          :total="total"
          @on-change="pageChange"
          simple
        ></Page>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="docListList"
      border
      stripe
      highlight-current-row
      :row-style="{ padding: '0px' }"
      :cell-style="{ padding: '0px 0' }"
      :header-row-style="{ padding: '2px 0' }"
      :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="文件编号"
        :show-overflow-tooltip="true"
        width="150"
        align="center"
        prop="docDjbh"
      />
      <el-table-column
        label="文件类型"
        :show-overflow-tooltip="true"
        width="120"
        align="center"
        prop="docType"
      >
        <template #default="scope">
          <dict-tag :options="docTypeOptions" :value="scope.row.docType" />
        </template>
      </el-table-column>
      <el-table-column
        label="文件名称"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="docName"
      />
      <el-table-column
        label="模具编号"
        :show-overflow-tooltip="true"
        width="150"
        align="center"
        prop="docMjbh"
      />
      <el-table-column
        label="模具名称"
        :show-overflow-tooltip="true"
        width="150"
        align="center"
        prop="docMjmc"
      />
      <el-table-column
        label="物料代码"
        :show-overflow-tooltip="true"
        width="130"
        align="center"
        prop="docWldm"
      />
      <el-table-column
        label="客户编码"
        width="150"
        align="center"
        prop="docCustwldm"
      />
      <el-table-column
        label="品名规格"
        :show-overflow-tooltip="true"
        width="200"
        prop="docPmgg"
      />
      <el-table-column
        label="图纸编号"
        width="150"
        align="center"
        prop="docTzbh"
      />
      <el-table-column
        label="适用吨位"
        width="100"
        align="center"
        prop="docJtdw"
      />
      <el-table-column
        label="适用机台"
        width="100"
        show-overflow-tooltip
        align="center"
        prop="docSyjt"
      />
      <el-table-column
        label="适用编号"
        width="100"
        show-overflow-tooltip
        align="center"
        prop="docSybh"
      />
      <el-table-column
        label="备注"
        width="120"
        show-overflow-tooltip
        align="center"
        prop="docDesc"
      />
      <el-table-column label="建立人员" align="center" prop="createBy" />
      <el-table-column
        label="建立日期"
        align="center"
        prop="createTime"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="100"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleImgLook(scope.row)"
            v-hasPermi="['project:docList:download']"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { listDocList, exportDocList } from "@/api/project/docList";

export default {
  name: "DocList",
  data() {
    return {
      // 遮罩层
      loading: true,
      tableH: null,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程文件表格数据
      docListList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 文件类型字典
      docTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        docDjbh: null,
        docType: null,
        docMjbh: null,
        docCustwldm: null,
        docTzbh: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("fileType").then((response) => {
      this.docTypeOptions = response.data;
    });
  },
  methods: {
    handleImgLook(a) {
      let files = process.env.VUE_APP_BASE_API + a.docPath;
      window.open(files);
    },
    /** 查询工程文件列表 */
    async getList() {
      this.loading = true;
      this.tableH = document.body.clientHeight - 280 > 600 ? 657 : 400;
      this.queryParams.pageSize = this.tableH > 600 ? 25 : 15;
      await listDocList(this.queryParams).then((response) => {
        this.docListList = response.rows;
        this.total = response.total;

        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        docDjbh: null,
        docName: null,
        docType: null,
        docMjbh: null,
        docWldm: null,
        docTzbh: null,
        docJtdw: null,
        docSyjt: null,
        docPath: null,
        docDesc: null,
        createBy: null,
        createTime: null,
        docLyid: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有工程文件数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportDocList(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.el-table .cell {
  white-space: nowrap;
}
</style>
